<div class="row">
    <div class="col-md-12">
        <div class="panel panel-default">
            <div class="panel-heading bg-orange">
                <h3 class="panel-title"><strong>Danh sách </strong> Images</h3>
            </div>
            <div class="panel-body">
                <div class="row">
                    <div class="col-md-12 m-b-20">
                        <a href="<?php echo Yii::app()->createUrl('/backend/images/update'); ?>" title="Thêm Image">
                            <div class="btn-group">
                                <button class="btn btn-danger" id="table-edit_new">
                                    <i class="fa fa-plus"></i> Thêm Image
                                </button>
                            </div></a>
                        <!--<div class="btn-group pull-right">
                            <button data-toggle="dropdown" class="btn btn-default dropdown-toggle">Tools <i class="fa fa-angle-down"></i>
                            </button>
                            <ul class="dropdown-menu pull-right">
                                <li><a href="#">In</a>
                                </li>
                                <li><a href="#">Xuất file PDF</a>
                                </li>
                                <li><a href="#">Xuất file Excel</a>
                                </li>
                            </ul>
                        </div>-->
                    </div>
                    <!-- end col -->
                    <div class="col-md-12 col-sm-12 col-xs-12 table-responsive table-orange">
                        <div role="grid" class="dataTables_wrapper form-inline" id="DataTables_Table_0_wrapper">
                            <div class="row">
                                <div class="col-xs-12 loadContent"></div>
                                <!--<div class="col-xs-6">
                                    <div id="DataTables_Table_0_length" class="dataTables_length">
                                        <label><select name="DataTables_Table_0_length" size="1" class="form-control" aria-controls="DataTables_Table_0">
                                                <option value="10" selected="selected">10</option>
                                                <option value="25">25</option>
                                                <option value="50">50</option>
                                                <option value="100">100</option>
                                            </select> </label></div>
                                </div>
                                <div class="col-xs-6">
                                    <div class="dataTables_filter" id="DataTables_Table_0_filter"><label><i class="fa fa-search"></i>
                                            <input type="text" class="form-control" aria-controls="DataTables_Table_0"></label></div>
                                </div>
                                -->
                            </div>
                            <?php $this->widget('zii.widgets.grid.CGridView', array(
                                    'id' => 'images-grid',
                                    'dataProvider' => $model->search(),
                                    'filter' => $model,
                                    'itemsCssClass' => 'table f-14 table-striped table-hover dataTable table-dynamic',
                                    'summaryCssClass' => 'col-xs-6',
                                    'summaryText' => '<div class="dataTables_info" id="DataTables_Table_0_info">Hiện {start} - {end} trong {count} dữ liệu</div>',
                                    'pagerCssClass' => 'col-xs-6 dataTables_paginate paging_bootstrap',
                                    'pager' => array(
                                        'header' => '',
                                        'selectedPageCssClass'=>'active',////default "selected"
                                        'hiddenPageCssClass'=>'disabled',//default "hidden"
                                        'htmlOptions'=>array('class'=>'pagination'),
                                        //'internalPageCssClass' => 'pagination' // page for li
                                        'maxButtonCount'=>2,//defalut 10
                                        'firstPageLabel'=>'<i class="fa fa-angle-double-left"></i>',
                                        'prevPageLabel'=>'<i class="fa fa-angle-left"></i>',
                                        'nextPageLabel'=>'<i class="fa fa-angle-right"></i>',
                                        'lastPageLabel'=>'<i class="fa fa-angle-double-right"></i>',
                                    ),
                                    //the same for our entire grid. Note that this value can be set to "false"
                                    //if you set this to false, you'll have to include the styles for grid in some of your css files
//                                    'cssFile'=>false,
                                    'template'=>"{items}\n{summary}\n{pager}",
                                    'columns' => array(
                                        array(
                                            'name' => 'id',
                                            'value' => '$data->id',
                                            'htmlOptions' => array(
                                                'style' => 'width: 3%'
                                            )
                                        ),
                                        'image_alt',
                                        'image_url',
                                        array(
                                            'name' => 'album_id',
                                            'value' => '$data->album->title'
                                        ),
                                        array(
                                            'name' => 'status',
                                            'value' => 'Lookup::item("STATUS", $data->status)'
                                        ),
                                        array(
                                            'class' => 'CButtonColumn',
                                            'htmlOptions' => array(
                                                'style' => 'width: 7%'
                                            ),
                                            'buttons'=>array(
                                                'delete' => array(
                                                    'label'=>'Delete',
                                                    'url'   => 'Yii::app()->controller->createUrl("delete", array("id" => $data->id))',
                                                    'click' => 'js:function() {deleteItem( $(this).attr("href") ); return false;}',
                                                    'options' => array(
                                                        'title'       => 'Update',
                                                        'id' => 'test'
                                                    ),
                                                ),
                                            ),
                                        ),
                                    ),
                                )
                            ); ?>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<?php
$scriptDelete = '
function deleteItem(url) {
    var id = parseInt(url.substring(url.indexOf("id=") + 3), 10);
    $.fn.yiiGridView.update("images-grid", {
        url: url,
        type: "post",
        data: { "id": id },
        beforeSend: function() {
//            $(".loading").show();
        },
        success: function(data){
            $(".loadContent").text(data);
            $.fn.yiiGridView.update("images-grid");
        }
    });
}
';
Yii::app()->clientScript->registerScript('scriptDelete', $scriptDelete, CClientScript::POS_END);